<?php
declare(strict_types = 1);

namespace app\api\validate;

use think\Validate;

class UserValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require',
        'phone_number' => 'require|mobile|length:11',
        'code' => 'require|number|min: 4',
        'type' => 'require|in:1,2',
        'sex' => 'require|in:1,2,3'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '用户名必须',
        'phone_number.require' => '手机号必须',
        'phone_number.mobile' => '不是正确手机号哦！',
        'phone_number.length' => '手机长度不够11位哟！',
        'code.require' => '验证码必须',
        'code.number' => '类型必须',
        'code.min' => '验证码长度不得低于4',
        'type.require' => '缓存时间必须',
        'type.in' => '类型数值错误',
        'sex.require' => '性别必须',
        'sex.in' => '类型数值错误！'
    ];

    // 验证码场景
    public function sceneCode()
    {
        return $this->only(['phone_number']);
    }

    // 前端登录验证
    public function scenePhone()
    {
        return $this->only(['phone_number','code','type']);
    }

    // 个人中心验证
    public function sceneUserInfo()
    {
        $this->only(['username','sex']);
    }
}
